package com.donn.securitycontrolplatform.user.controller;


import com.dahuatech.icc.exception.ClientException;
import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.expection.BusinessException;
import com.donn.securitycontrolplatform.user.entity.DaHuaPerson;
import com.donn.securitycontrolplatform.user.entity.PersonBase;
import com.donn.securitycontrolplatform.user.entity.TUser;
import com.donn.securitycontrolplatform.user.request.UserReq;
import com.donn.securitycontrolplatform.user.service.ITUserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author zhenglixiang
 * @since 2022-06-10
 */
@RestController
@RequestMapping("/scp/api/user/info")
@Tag(name = "user-controller", description = "用户接口")
public class TUserController {
    @Autowired
    ITUserService userService;

//
//    @ApiOperation(value = "测试POST方法", notes = "测试POST方法")
//    @ApiImplicitParam(name = "令牌", value = "ID", required = true, dataType = "token")
//    @RequestMapping(value = "hello", method = RequestMethod.POST)
//    public String post(@RequestBody String token) {
//        books.put(book.getId(), book);
//        return "success";
//    }




    @ApiOperation(value = "用户信息删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "人员id")
    })
    @DeleteMapping(value = "/synchronizeDelete")
    @ResponseBody
    public Result synchronizeDelete(@RequestParam Integer userId) throws BusinessException, ClientException {
        return userService.synchronizeDelete(userId);
    }


    @ApiOperation(value = "用户信息编辑")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "人员id")
    })
    @PostMapping(value = "/synchronizeUpdate")
    @ResponseBody
    public Result synchronizeUpdate(@RequestBody DaHuaPerson person) throws BusinessException, ClientException {
        return userService.synchronizeUpdate(person);
    }

    @ApiOperation(value = "用户信息修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名"),
            @ApiImplicitParam(name = "sex", value = "性别"),
            @ApiImplicitParam(name = "iden", value = "身份证"),
            @ApiImplicitParam(name = "createBy", value = "创建人")
    })
    @PutMapping("/update")
    @ResponseBody
    public Result update(@RequestBody TUser user) {
        return userService.update(user);
    }

    @ApiOperation(value = "用户信息查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名"),
            @ApiImplicitParam(name = "sex", value = "性别"),
            @ApiImplicitParam(name = "iden", value = "身份证"),
            @ApiImplicitParam(name = "createBy", value = "创建人"),
            @ApiImplicitParam(name = "size", value = "条数"),
            @ApiImplicitParam(name = "current", value = "当前页")
    })
    @GetMapping("/list")
    @ResponseBody
    public Result list(UserReq req) {
        return userService.selectUserList(req.getUser(), req.getPage());
    }

    @ApiOperation(value = "用户信息删除，通过用户userId删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id")
    })
    @DeleteMapping("/delete")
    public Result deleteInfo(@RequestParam Long userId) {
        return userService.deleteUser(userId);
    }

    @ApiOperation(value = "用户详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户Id")
    })
    @GetMapping("/get")
    @ResponseBody
    public Result get(@RequestParam Long userId) {
        return userService.getUserById(userId);
    }

}
